<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
<input type="text">
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
<script>
    const arr = [{
        time: "2021-1-1",
        type: "早班",
        num: 10
    },
        {
            time: "2021-1-1",
            type: "早班",
            num: 10
        },
        {
            time: "2021-1-1",
            type: "中班",
            num: 10
        },
        {
            time: "2021-1-1",
            type: "晚班",
            num: 10
        },
        {
            time: "2021-1-2",
            type: "早班",
            num: 10
        },
        {
            time: "2021-1-2",
            type: "中班",
            num: 10
        },
        {
            time: "2021-1-2",
            type: "晚班",
            num: 10
        },
        {
            time: "2021-1-3",
            type: "早班",
            num: 10
        },
        {
            time: "2021-1-3",
            type: "中班",
            num: 10
        },
        {
            time: "2021-1-3",
            type: "晚班",
            num: 10
        }
    ]
    const a = _.chain(arr).groupBy('time').map(item => {
        return _.values(_.groupBy(item, 'type'))
    }).value()
    console.log(a)

    // const timeList = Array.from(new Set(arr.reduce((total, item) => total.concat(item.time), [])))
    // const newarr = []
    // const newarrList = Array(timeList.length).fill([])
    // const newarrType = ['早班', '中班', '晚班']
    // timeList.forEach(item => {
    //     newarr.push(arr.filter(value => value.time === item))
    // })
    //
    //
    // const arr1 = newarr
    // let gResult = []
    // let result = new Array()
    // for (let j = 0; j < newarr.length; j++) {
    //     result=[]
    //     let mi = 0
    //     gResult = _.groupBy(newarr[j], 'type')
    //     _.map(gResult, (item,index,s)=>{
    //         result[mi] = new Array()
    //         console.log(item)
    //         for (let k = 0; k <item.length ; k++) {
    //             result[mi][k] = item[k]
    //         }
    //         mi++
    //     });
    //     arr1[j] = result
    // }
    // console.log(arr1)
    //
    // console.log(_.flattenDeep(arr1))

    // const newarr = [
    //     [
    //         [
    //             { time: "2021-1-1", type: "早班", num: 10 },
    //             { time: "2021-1-1", type: "早班", num: 10 },
    //         ],
    //         [
    //             { time: "2021-1-1", type: "中班", num: 10 },
    //         ],
    //         [
    //             { time: "2021-1-1", type: "晚班", num: 10 },
    //         ],
    //     ],
    //     [
    //         [
    //             { time: "2021-1-2", type: "早班", num: 10 },
    //             { time: "2021-1-2", type: "早班", num: 10 }
    //         ],
    //         [{ time: "2021-1-2", type: "中班", num: 10 },
    //         { time: "2021-1-2", type: "中班", num: 10 }],
    //         [{ time: "2021-1-2", type: "晚班", num: 10 },
    //         { time: "2021-1-2", type: "晚班", num: 10 }]
    //     ],
    //     [
    //         [{ time: "2021-1-3", type: "早班", num: 10 }],
    //         [{ time: "2021-1-3", type: "中班", num: 10 }],
    //         [{ time: "2021-1-3", type: "晚班", num: 10 }]
    //     ]
    // ]
    // const obj = { time: '', type: '班合计', num: "" }
    // const obj1 = { time: '', type: '日合计', num: "" }
    // newarr.forEach(item => {
    //     item.forEach(value => {
    //         const object = Object.assign({}, obj)
    //         let number = value.reduce((total, pre) => total + pre.num, 0)
    //         object.num = number
    //         value.push(object)
    //     })
    // })
    // newarr.forEach(item => {
    //     const object = Object.assign({}, obj1)
    //     let number = item.flat().reduce((total, pre) => total + pre.num, 0)
    //     object.num = number / 2
    //     item.push(object)
    // })
    // let newarr1 = newarr.flat(Infinity)
    // console.log(newarr1)
</script>
</body>

</html>